﻿
using System ;
using System.Drawing ;
using System.Configuration ;
using System.ComponentModel ;


namespace MskEdit.Msk.Model
{
    public class MskProperties
    {
        #region Private data
        
        private string      mskFileName_ ;
        private MskPageKey  mskPageKey_ ;
        private MskLine     mskLine_ ;
        
        #endregion
        
        #region Public events
        
        public delegate void PropertiesChangedEventHandler() ;
        public event PropertiesChangedEventHandler PropertiesChanged ;
        
        public delegate void LineContentChangedEventHandler( MskLine mskLine ) ;
        public event LineContentChangedEventHandler LineContentChanged ;
        
        #endregion
        
        #region Private operations

        private void InvokePropertiesChanged() {
            if ( PropertiesChanged != null )
                PropertiesChanged.Invoke() ;
        }
        
        
        private void setMskLineXYk( Point XYk ) {
            
            Point oldXYk = mskLine_.XYk ;
            if ( oldXYk == XYk )
                return ;
                
            mskLine_.XYk = XYk ;
            
            if ( LineContentChanged !=null )
                LineContentChanged.Invoke( mskLine_ ) ;
        }
        

        private void setMskLineCaption( string caption ) {
            
            string oldCaption = mskLine_.Caption ;
            if ( oldCaption == caption )
                return ;
                
            mskLine_.Caption = caption ;
            
            if ( LineContentChanged !=null )
                LineContentChanged.Invoke( mskLine_ ) ;
        }
        
        #endregion
        
        #region Public foundation

        public MskProperties() {
            mskFileName_ = "" ;
            mskPageKey_ = MskPageKey.NullPageKey ;
            mskLine_ = MskLine.NullLine ;
        }
        
        #endregion       

        #region File properties

        [Browsable( false )]
        public string MskFileName {
            get { 
                return mskFileName_ ; 
            }
            set { 
                mskFileName_ = value ;
                InvokePropertiesChanged() ;
            }
        }


        [Category( "\t\tMsk File properties" )]
        [DisplayName( "File name" )]
        [Description( "Current MSK file." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string fileNameProperty {
            get { return mskFileName_ ; }
        }
        
        #endregion
        
        #region Page properties
        
        [Browsable( false )]
        public MskPageKey MskPageKey {
            set { 
                mskPageKey_ = value ;
                InvokePropertiesChanged() ;
            }
        }


        [Category( "\tMsk Page properties" )]
        [DisplayName( "Language code" )]
        [Description( "Display language of current page." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string languageProperty {
            get { return mskPageKey_.Language.ToString() ; }
        }
        

        [Category( "\tMsk Page properties" )]
        [DisplayName( "Page code" )]
        [Description( "Page code of current page." )]
        [DefaultSettingValueAttribute( "0" )]
        [UserScopedSettingAttribute()]
        public int pageCodeProperty {
            get { return mskPageKey_.PageCode.Code ; }
        }
        
        #endregion
        
        #region Line properties
        
        [Browsable( false )]
        public MskLine MskLine {
            set { 
                mskLine_ = value ;
                InvokePropertiesChanged() ;         
            }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tField name" )]
        [Description( "Name of database field." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string FieldNameProperty {
            get { return mskLine_.FieldName ; }
        }
        

        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\t\t\t\t\t\t\tField length" )]
        [Description( "Database field length of current data item." )]
        [DefaultSettingValueAttribute( "0" )]
        [UserScopedSettingAttribute()]
        public int LenProperty {
            get { return mskLine_.Len ; }
        }
        

        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\t\t\t\t\t\tCaption position" )]
        [Description( "Position of selected MSK line." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public Point CaptionPositionProperty {
            get { return mskLine_.XYk ; }
            set { setMskLineXYk( value ) ; }
        }
        

        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\t\t\t\t\tType" )]
        [Description( "Type of current data item." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string TypeProperty {
            get { return mskLine_.Type ; }
        }
        

        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\t\t\t\tDecimals" )]
        [Description( "Number of decimal digits in numeric field types." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public int DecimalsProperty {
            get { return mskLine_.Decimals ; }
        }
        

        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\t\t\tCaption" )]
        [Description( "Caption of selected MSK line." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string CaptionProperty {
            get { return mskLine_.Caption ; }
            set { setMskLineCaption( value ) ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\t\tFunction code" )]
        [Description( "Specifies functionality of this field in the drawing manager." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string FunctionCodeProperty {
            get { return mskLine_.FunctionCode.ToString() ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\t\tSheet coordinates" )]
        [Description( "Coordinates for where this fiald can be found in the drawing sheet." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public PointF AcadXYProperty {
            get { return mskLine_.AcadXY ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\t\tText height" )]
        [Description( "Height of text in drawing window." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string HeightProperty {
            get { return mskLine_.AcadHeight ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\t\tText style" )]
        [Description( "Style of text in drawing window." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string StyleProperty {
            get { return mskLine_.AcadStyle ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\t\tText angle" )]
        [Description( "Angle of text in drawing window." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string AngleProperty {
            get { return mskLine_.AcadAngle ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\t\tText layer" )]
        [Description( "Layer of text in drawing window." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string LayerProperty {
            get { return mskLine_.AcadLayer ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\t\tText alignment" )]
        [Description( "Alignment of text in drawing window." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string AlignmentProperty {
            get { return mskLine_.AcadAlignment; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\t\tHelp text" )]
        [Description( "The tooltip text shown in the detail view window." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string HelpTextProperty {
            get { return mskLine_.HelpText ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "\tAcad block" )]
        [Description( "The name of the block where the attribute is located in the drawing sheet." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string AcadBlockProperty {
            get { return mskLine_.AcadBlock ; }
        }


        [Category( "Msk Line properties" )]
        [DisplayName( "Acad tag" )]
        [Description( "The attribute tag name in the drawing sheet." )]
        [DefaultSettingValueAttribute( "" )]
        [UserScopedSettingAttribute()]
        public string AcadTagProperty {
            get { return mskLine_.AcadTag ; }
        }

        #endregion

    }
}
